
# b=3
# c=1
tmp=list(map(int,input().split()))
c=tmp[0]
b=tmp[1]
arr=tmp[2:]

def classify(a):
    s=hex(a)[2:]
    if len(s)%2 !=0:
        s="0"+s
    sumV=0
    for i in range(0,len(s)-1,2):
        sumV=sumV+int(s[i:i+2],16)
    # return sumV
    t= sumV%b
    if t<c:
        return t
    else:
        return -1
# print(123)
def getResult():
    count={}
    for t in map(classify,arr):
        if t!=-1:
            if count.get(t) is None:
                count[t]=1
            else:
                count[t]=count[t]+1
    return max(count.values())
print(getResult())
# 3 4 256 257 258 259 260 261 262 263 264 265



